#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 510;

/*
we can find that elements in the same slash is in the same set
so we can compare these set to check wheather we can change matrice A to B

*/

int n, m;
int g1[N][N], g2[N][N];
vector<int> f1[N * 3], f2[N * 3];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cin >> g1[i][j];
            f1[i + j].push_back(g1[i][j]);
        }
    }

    
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cin >> g2[i][j];
            f2[i + j].push_back(g2[i][j]);
        }
    }

   

    for(int i = 2; i <= n + m; i ++){
        sort(f1[i].begin(), f1[i].end());
        sort(f2[i].begin(), f2[i].end());
    }

    for(int i = 2; i <= n + m; i ++){
        if(f1[i] != f2[i]){
            cout << "NO" << '\n';
            exit(0);
        }
    }

    cout << "YES" << '\n';




    return 0;
}